package com.wyb.hzmt.static_baseFrame_tools0.tools;

import android.content.Context;
import android.content.SharedPreferences;

import com.wyb.hzmt.static_baseFrame_tools0.framework.MyApplication;

/**
 * Created by Administrator on 2017/3/6.
 *
 */

public class MySharedPerfHelper {
    /**
     * SharedPreferences的名字
     */
    private static final String SP_FILE_NAME = "APPLICATION_SP";
    private static MySharedPerfHelper sharedPrefHelper = null;
    private static SharedPreferences sharedPreferences;
    private boolean netStatus;

    public static synchronized MySharedPerfHelper getInstance() {
        if (null == sharedPrefHelper) {
            sharedPrefHelper = new MySharedPerfHelper();
        }
        return sharedPrefHelper;
    }

    private MySharedPerfHelper() {
        sharedPreferences = MyApplication.getInstance().getSharedPreferences(SP_FILE_NAME, Context.MODE_PRIVATE);
    }

    // 用户名字
    public void setUserName(String userName) {
        sharedPreferences.edit().putString("username", userName).commit();
    }

    public String getUserName() {
        return sharedPreferences.getString("username", "");
    }

    // 登录密码：
    public void setLoginPassword(String password) {
        sharedPreferences.edit().putString("password", password).commit();
    }


    public String getLoginPassword() {
        return sharedPreferences.getString("password", "");
    }

    //用户所属处
    public void setChu(String chu){
        sharedPreferences.edit().putString("chu", chu).commit();
    }

    public String getChu() {
        return sharedPreferences.getString("chu", "");
    }

    //登录Token
    public void setLoginToken(String mToken) {
        sharedPreferences.edit().putString("mToken", mToken).commit();
    }

    public String getLoginToken() {
        return sharedPreferences.getString("mToken", "");
    }

    //注册成功返回id
    public void setId(String id) {
        sharedPreferences.edit().putString("id", id).commit();
    }

    public String getId() {
        return sharedPreferences.getString("id", "");
    }

    // 2017/4/14 高清图
    public void setIsHDPic(boolean isHDPic) {
        sharedPreferences.edit().putBoolean("HDPic", isHDPic).commit();
    }

    public boolean isHdPic() {
        return sharedPreferences.getBoolean("HDPic", false);
    }

    public void setAddEvebts(boolean isCanAdd){
        sharedPreferences.edit().putBoolean("isCanAdd", isCanAdd).commit();
    }

    public boolean isAddEvents() {
        return sharedPreferences.getBoolean("isCanAdd", false);

    }

    // 2017/4/14 自动更新
    public void setIsAutoUpdate(boolean isAutoUpdate) {
        sharedPreferences.edit().putBoolean("IsAutoUpdate", isAutoUpdate).commit();
    }

    public boolean isAutoUpdate() {
        return sharedPreferences.getBoolean("IsAutoUpdate", false);

    }

    public void setIsSaveEvent(boolean isSaveEvent){
        sharedPreferences.edit().putBoolean("isSaveEvent", isSaveEvent).commit();
    }

    public boolean isSaveEvent() {
        return sharedPreferences.getBoolean("isSaveEvent", false);
    }

    public void setIsSaveEmerEvent(boolean isSaveEmerEvent){
        sharedPreferences.edit().putBoolean("isSaveEmerEvent", isSaveEmerEvent).commit();
    }

    public boolean isSaveEmerEvent() {
        return sharedPreferences.getBoolean("isSaveEmerEvent", false);
    }

    public void setErrorInfo(String ErrorInfo){
        sharedPreferences.edit().putString("ErrorInfo",ErrorInfo).commit();
    }

    public String getErrorInfo(){
        return sharedPreferences.getString("ErrorInfo","");
    }

    public void setDeviceInfo(String DeviceInfo){
        sharedPreferences.edit().putString("DeviceInfo",DeviceInfo).commit();
    }

    public String getDeviceInfo(){
        return sharedPreferences.getString("DeviceInfo","");
    }


    //删除所有xml内容
    public void removeAll() {
        sharedPreferences.edit().remove("username").commit();//apply提交是异步的无返回的，不安全
        sharedPreferences.edit().remove("password").commit();
        sharedPreferences.edit().remove("chu").commit();
        sharedPreferences.edit().remove("id").commit();
        sharedPreferences.edit().remove("HDPic").commit();
        sharedPreferences.edit().remove("isCanAdd").commit();
        sharedPreferences.edit().remove("IsAutoUpdate").commit();
        sharedPreferences.edit().remove("isSaveEvent").commit();
        sharedPreferences.edit().remove("isSaveEmerEvent").commit();
        sharedPreferences.edit().remove("Event").commit();
        sharedPreferences.edit().remove("EmerEvent").commit();
        sharedPreferences.edit().remove("netStatus").commit();
    }

    public boolean getNetStatus() {
        return netStatus;
    }

    public void setNetStatus(boolean netStatus) {
        sharedPreferences.edit().putBoolean("netStatus", netStatus).apply();
    }
}
